package com.sakura.mall.product.attrAttrgroupRelation.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.product.attrAttrgroupRelation.domain.request.AddAttrAttrgroupRelationRequest;
import com.sakura.mall.product.attrAttrgroupRelation.domain.request.UpdateAttrAttrgroupRelationRequest;
import com.sakura.mall.product.attrAttrgroupRelation.domain.request.AttrAttrgroupRelationPageRequest;
import com.sakura.mall.product.attrAttrgroupRelation.service.AttrAttrgroupRelationService;
import com.sakura.mall.product.attrAttrgroupRelation.domain.vo.AttrAttrgroupRelationVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 属性&属性分组关联
 *
 * @author sakura
 */
@RestController
@RequestMapping("/attrAttrgroupRelation")
@RequiredArgsConstructor
public class AttrAttrgroupRelationController {

    private final AttrAttrgroupRelationService attrAttrgroupRelationService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddAttrAttrgroupRelationRequest request) {
        attrAttrgroupRelationService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<AttrAttrgroupRelationVo>}
     */
    @GetMapping("list")
    public R<Page<AttrAttrgroupRelationVo>> page(AttrAttrgroupRelationPageRequest request) {
        Page<AttrAttrgroupRelationVo> ret = attrAttrgroupRelationService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        attrAttrgroupRelationService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateAttrAttrgroupRelationRequest request) {
        attrAttrgroupRelationService.updateById(id, request);
        return R.ok();
    }

}
